package com.b2b.common.web;

import com.b2b.common.typewrap.Dto;
import com.b2b.common.typewrap.impl.HashDto;

import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by Soldier lee on 2016-11-09.
 */
public class WebCxt {


    /**
     * 将Request请求参数封装为Dto对象
     *
     * @param request
     * @return
     */
    @SuppressWarnings("all")
    public static Dto getParamAsDto(HttpServletRequest request) {
        Dto dto = new HashDto();
        Map<String, String[]> map = request.getParameterMap();
        Iterator<String> keyIterator = (Iterator) map.keySet().iterator();
        while (keyIterator.hasNext()) {
            String key = (String) keyIterator.next();
            String value = map.get(key)[0];
            dto.put(key, value);
        }
        return dto;
    }
}
